package com.kgc.server.controller;

import com.kgc.server.pojo.Easybuy_product_category;
import com.kgc.server.service.EasybuyProductCategoryService;
import com.kgc.server.util.ResponseMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class EasybuyProductCategoryController {

    private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private EasybuyProductCategoryService easybuyProductCategoryService;


    @ResponseBody
    @RequestMapping("getProductTypeName")
    @CrossOrigin
    public ResponseMessage getProductTypeName(){

        ResponseMessage productType = easybuyProductCategoryService.getProductType();
        return  productType;
    }

    @ResponseBody
    @RequestMapping("getProductTypes")
    @CrossOrigin
    public ResponseMessage getProductTypes(Integer parentId,Integer typeId){
        logger.info("EasybuyProductCategoryController getProductTypes params: parentId"+parentId+";typeId"+typeId);
        ResponseMessage msg = easybuyProductCategoryService.getProductTypes(parentId, typeId);
        logger.info("EasybuyProductCategoryController getProductTypes params: parentId"+parentId+";typeId"+typeId+";result:"+msg);
        return msg;
    }

    @ResponseBody
    @RequestMapping("showProductType3")
    @CrossOrigin
    public ResponseMessage showProductType3(){
        logger.info("EasybuyProductCategoryController showProductType3 start..");
        ResponseMessage msg = easybuyProductCategoryService.showProductType3();
        return msg;
    }

    @ResponseBody
    @RequestMapping("addProductType")
    @CrossOrigin
    public ResponseMessage addProductType(Easybuy_product_category easybuy_product_category){
        logger.info("EasybuyProductCategoryController addProductType params:"+easybuy_product_category);
        ResponseMessage msg = easybuyProductCategoryService.addProductType(easybuy_product_category);
        return msg;

    }

    @ResponseBody
    @RequestMapping("showProductTypeByPage")
    @CrossOrigin
    public ResponseMessage showProductTypeByPage(Integer pageNo,Integer type,String name){
        logger.info("EasybuyProductCategoryController showProductTypeByPage params:pageNo："+pageNo+";type:"+type+";name:"+name);
        ResponseMessage msg = easybuyProductCategoryService.showProductTypeByPage(name, type, pageNo);
        return msg;

    }

    @ResponseBody
    @RequestMapping("modifyType")
    @CrossOrigin
    public ResponseMessage modifyType(Easybuy_product_category easybuy_product_category){
        logger.info("EasybuyProductCategoryController showProductTypeByPage params:easybuy_product_category："+easybuy_product_category);
        ResponseMessage msg = easybuyProductCategoryService.modifyType(easybuy_product_category);
        return msg;
    }

    @ResponseBody
    @RequestMapping("delProductType")
    @CrossOrigin
    public ResponseMessage delProductType(Integer id){
        logger.info("EasybuyProductCategoryController delProductType params　id: "+id);
        ResponseMessage msg = easybuyProductCategoryService.delProductType(id);
        return msg;
    }

    @ResponseBody
    @RequestMapping("getTypeById")
    @CrossOrigin
    public ResponseMessage getTypeById(Integer id){
        logger.info("EasybuyProductCategoryController getTypeById param id: "+id);
        ResponseMessage msg = easybuyProductCategoryService.getTypeById(id);
        return msg;
    }
}
